package com.mangohouse.service.core.impl;

import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;

import org.springframework.stereotype.Service;

import com.mangohouse.dao.core.ISysMenuDao;
import com.mangohouse.model.core.SysMenu;
import com.mangohouse.model.core.SysUser;
import com.mangohouse.service.ServiceException;
import com.mangohouse.service.core.ISysMenuService;

/**
 * 
 * @TODO 系统菜单业务层实现类
 * @author roye
 * @date May 3, 2013 10:17:07 AM
 * @version V1.0
 */
@Service
public class CSysMenuServiceImpl implements ISysMenuService {

	
	@Resource
	private ISysMenuDao sysMenuDao;
	
	
	/**
	 * 获取用户权限
	 */
	public String getPrivilegeMenuByUser(SysUser user)
			throws ServiceException {
		List<SysMenu> rstList = sysMenuDao.getPrivilegeMenuByUser(user);
		JSONArray json = new JSONArray();
		try {
			for (int j = 0; j < rstList.size(); j++) {
				SysMenu menu = (SysMenu) rstList.get(j);
				JSONObject jo = new JSONObject();
				jo.put("id", menu.getMenuId());
				jo.put("name", menu.getMenuName());
				jo.put("pId", menu.getMenuParentId());
				jo.put("path", menu.getMenuUrl());
				jo.put("target", "mainFrame");
				jo.put("icon", menu.getMenuPicture());
				json.add(jo);
			}
		} catch (JSONException e) {
			throw e;
		}
		return json.toString();
	}

}
